
import {storeBindingsBehavior} from "mobx-miniprogram-bindings";
import base from '@src/store/base';
Component({
  behaviors: [storeBindingsBehavior],
  storeBindings: [{
    store: base,
    fields: ['isiPhoneX', 'themeColor', 'themeTitleColor']
  }],
  /**
   * 组件的属性列表
   */

  properties: {
    showDialog: {
      type: Boolean,
      value: false
    },
    //预售弹框类型  1预售须知条款，2.取消预售条款
    saleType: {
      type: Number,
      value: 1
    },
    goodsTitle: {
      type: String,
      value: "",
    },
    hiddenBottomBtn: {
      type: Boolean,
      value: true
    },
    goodsPresell: {
      type: Object,
      value: {},
      observer: function (goodsPresell) {
        console.log('goodsPresell', goodsPresell)
        if(goodsPresell&&goodsPresell.remark){
          let remark = goodsPresell.remark.split(/[(\r\n)\r\n]+/);
          this.setData({remark:remark})
          remark.forEach((item)=>{console.log(item)})
        }
        // console.log("remark",goodsPresell.remark,remark)
      }
    },
    orderPresellForm: {
      type: Object
    },
    title: {
      type: String,
      value: '商品预售条款'
    },
    subType: {
      type: String
    },
    //全款预售金额
    price: {
      type: String
    },
    //定金金额
    deposit: {
      type: String,
      observer: function (deposit) {
        console.log("deposit", deposit)
      }
    },
    //尾款金额
    remaining: {
      type: String,
      observer: function (remaining) {
        console.log("remaining", remaining)
      }
    },
    selectSkuObj: {
      type: Object,
    },
    deliveryType: {
      type: String
    }
  },
  options: {
    addGlobalClass: true
  },

  /**
   * 组件的初始数据
   */
  data: {
    contentHeight: 600,
    remark:[],
  },

  /**
   * 组件生命周期
   */
  lifetimes: {
    created: function (val) {

    },
    attached: function (val) {

    },
    ready: function (val) {


    },

    moved: function () {

    },
    detached: function () {

    },
  },

  /**
   * 组件所在页面生命周期
   */
  pageLifetimes: {},

  /**
   * 组件的方法列表
   */
  methods: {
    open() {
      this.setData({showDialog: true})
    },
    close() {
      this.setData({showDialog: false})
    },
    submitPreSell() {
      this.close();
      if (this.data.saleType === 2) {
        //已付定金，且不能取消
        console.log("orderPresellForm", this.data.orderPresellForm)
        console.log("this.data.orderPresellForm.cancelRule ", this.data.orderPresellForm.canCancel);
        console.log("!this.data.orderPresellForm.cancelRule ", !this.data.orderPresellForm.canCancel);
        console.log("this.data.goodsPresell.type", this.data.goodsPresell.type);
        console.log("this.data.orderPresellForm.remainingStatus", this.data.orderPresellForm.remainingStatus);
        console.log("this.data.orderPresellForm.depositStatus", this.data.orderPresellForm.depositStatus)
        if (this.data.goodsPresell.type === 'DEPOSIT' && (this.data.orderPresellForm.depositStatus === 1) && (!this.data.orderPresellForm.canCancel)) {
          return;
          //全款 已付
        } else if (this.data.goodsPresell.type === 'FULL' && this.data.orderPresellForm.remainingStatus === 1 && (!this.data.orderPresellForm.canCancel)) {
          return;
        } else {
          this.triggerEvent("submitPreSell");
          return;
        }
      }
      this.triggerEvent("submitPreSell");
    },
    onContentHeight(val) {
      this.setData({
        contentHeight: val.detail
      })
    },
  }
})
